# -*- coding: utf-8 -*-
#
# Author:: JonnyHan
# Date:: 2020/12/22
import time


def get_exec_time(code):
    t1 = time.time()
    exec(code)
    t2 = time.time()
    return t2 - t1


def get_obj_methods(obj):
    return obj.__dir__()


def get_obj_attrs(obj):
    return obj.__dict__(obj)


def print_obj_methods(obj):
    # res = visual_obj.__dir__()
    # print(res)
    # for method_name in res:
    #     if "__" in method_name:
    #         print("function_name:" + method_name)
    #         code = 'print(driver.%s())' % method_name
    #         try:
    #             exec(code)
    #         except:
    #             pass

    # todo 无法使用主程序引入的对象
    # NameError: name '_data' is not defined
    pass


def print_obj_attrs(obj):
    # res = visual_obj.__dict__
    # obj_name = visual_obj.__name__.split(".")[-1]
    # print(res)
    # for attr_name in res:
    #     print("attr_name:" + attr_name)
    #     code = 'print(%s.%s)' % (obj_name, attr_name)
    #     print(code)
    #     try:
    #         exec(code)
    #     except:
    #         pass

    # todo 无法使用主程序引入的对象
    # NameError: name '_data' is not defined
    pass


if __name__ == "__main__":
    def get_exec_time_test():
        code = '''
import requests
for i in range(10):
    r = requests.get("http://www.baidu.com")
print(r.status_code)
'''
        r = get_exec_time(code)
        print(r)

    # get_exec_time_test()
